
import { _decorator, Component, Node, resources, Prefab, instantiate } from 'cc';
import { Message } from './Message'
import { ModuleBase } from './ModuleBase';
const { ccclass, property } = _decorator;


@ccclass('ModuleCenter')
export class ModuleCenter {

    /**
     * 发送消息
     * @param msg 
     */
    public static pushMessage(msg: Message) {
        for (let index = 0; index < ModuleBase.modules.length; index++) {
            if (ModuleBase.modules[index].moduleName === msg.ModuleName) {
                ModuleBase.modules[index].ReceiveMessage(msg);
            }
        }
    }
    /**
     * 通过模块名获取
     * @param ModuleName 模块名
     * @returns 
     */
    public static getModule(ModuleName: string): ModuleBase {
        for (let index = 0; index < ModuleBase.modules.length; index++) {
            if (ModuleBase.modules[index].moduleName === ModuleName) {
                return ModuleBase.modules[index];
            }
        }
        return null
    }
}

